/**
 * 1表示一级目录界面 2表示二级文件页面
 * @type {number}
 */
var page_level = 1;

function getAllFolder() {
    $.ajax({
            url: address_head + "/api/SelectAllFolder",
            async: true,
            type: "POST",
            success: function (data) {
                console.log(data);
                $("#flodername").remove();
                $("#folder_list").html("")
                for (i in data) {// data.data指的是数组，数组里是对象，i为数组的索引
                    console.log(data[i]);
                    $html = $("<div onclick='getAllFile(\"" + data[i] + "\")'> <img src=\"image/filefloder.png\"><p>" + data[i] + "</p></div>");
                    $("#folder_list").append($html);
                }
            },
            error:
                function () {
                    alert("请求失败");
                },
            dataType: "json"
        }
    );
}


function getAllFile(filefolder1) {
    console.log("filefolder:" + filefolder1);
    $.ajax({
            url: address_head + "/api/SelectFileInFolder",
            async: true,
            type: "POST",
            // 成功后开启模态框
            data: JSON.stringify({
                filefolder: filefolder1
            }),
            dataType: 'json',
            contentType: 'application/json;charset=UTF-8',
            success: function (data) {
                page_level = 2;
                $html =$("<li id='flodername'>"+filefolder1+"</li>");
                $("#direction_list").append($html);
                $("#folder_list").html("")
                for (i in data) {// data.data指的是数组，数组里是对象，i为数组的索引
                    console.log(data[i]);
                    var filetype = "";
                    if (data[i].filetype == "exe") {
                        filetype = "image/exe.png";
                    } else if (data[i].filetype == "zip") {
                        filetype = "image/zip.png";
                    } else if (data[i].filetype == "rar") {
                        filetype = "image/zip.png";
                    } else if (data[i].filetype == "msi") {
                        filetype = "image/msi.png";
                    }
                    $html = $("<div> <img src ='" + filetype + "'/><a href='" + data[i].location + "'><p>" + data[i].name + "</p></a></div>");
                    $("#folder_list").append($html);
                }
            },

            error:
                function () {
                    alert("请求失败");
                },
            dataType: "json"
        }
    );
}